package com.jyh.controller;



import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;


import com.jyh.service.SuperviseService;




/**
 * 管理权限方法
 * @author xuyang
 *
 * @param <V>
 */
@Controller
@RequestMapping(value = "/supervise")
public class JurisdictionController {
	private static Logger logger = Logger.getLogger(JurisdictionController.class);
	@Autowired
	private SuperviseService superviseService;
	


	/**
	 * 管理员页面查询
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/getManager")
	public ModelAndView getManager(HttpServletRequest request,HttpSession session) {
		try {
			logger.info("begin");
			ModelAndView mv = superviseService.getManager(request, session);
			return mv;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("\n -------------error信息开始-------------- \n" + e + "\n -----------------error信息结束------------------\n\n");
			return null;
		}	
	}
	

	/**
	 * 管理员页面查询
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/roleList")
	public ModelAndView getRoleList(HttpServletRequest request,HttpSession session) {
		try {
			logger.info("begin");
			ModelAndView mv = superviseService.getRoleList(request, session);
			return mv;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("\n -------------error信息开始-------------- \n" + e + "\n -----------------error信息结束------------------\n\n");
			return null;
		}	
	}

	/**
	 * 管理员页面查询
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/roleList1")
	public ModelAndView getRoleList1(HttpServletRequest request,HttpSession session) {
		try {
			logger.info("begin");
			ModelAndView mv = superviseService.getUpdateManager1(request, session);
			return mv;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("\n -------------error信息开始-------------- \n" + e + "\n -----------------error信息结束------------------\n\n");
			return null;
		}	
	}


	/**
	 * 修改管理员权限
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/getManagerID")
	public ModelAndView getManagerID(HttpServletRequest request,HttpSession session) {
		try {
			logger.info("begin");
			ModelAndView mv = superviseService.getUpdateManager(request, session);
			return mv;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("\n -------------error信息开始-------------- \n" + e + "\n -----------------error信息结束------------------\n\n");
			return null;
		}	
	}

	/**
	 * 修改管理员密码
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/getManagerU")
	@ResponseBody
	public String getManagerU(HttpServletRequest request,HttpSession session) {
		try {
			logger.info("begin");
			String str = superviseService.getManagerU(request, session);
			return str;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("\n -------------error信息开始-------------- \n" + e + "\n -----------------error信息结束------------------\n\n");
			return null;
		}	
	}

	
	/**
	 * 新政管理员权限
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/getAddManager")
	public ModelAndView getAddManager(HttpServletRequest request,HttpSession session) {
		try {
			logger.info("begin");
			ModelAndView mv = superviseService.getAddManager(request, session);
			return mv;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("\n -------------error信息开始-------------- \n" + e + "\n -----------------error信息结束------------------\n\n");
			return null;
		}	
	}
	
	/**
	 * 修改管理员权限
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/getManagerI")
	@ResponseBody
	public String getManagerI(HttpServletRequest request,HttpSession session) {
		try {
			logger.info("begin");
			String str = superviseService.getManagerI(request, session);
			return str;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("\n -------------error信息开始-------------- \n" + e + "\n -----------------error信息结束------------------\n\n");
			return null;
		}	
	}
	
	@RequestMapping(value = "/showJurisdiction")
	public ModelAndView showJurisdiction(HttpServletRequest request, HttpSession session) {
		logger.info(" 权限视图罗列 - " + Thread.currentThread().getStackTrace()[1].getMethodName() + " - start $");
		ModelAndView mv = new ModelAndView("jurisdiction/showJurView");
		String view = "";
		String rid = request.getParameter("id");
		if( rid != null && !"".equals(rid) ){
			view = superviseService.getJrData(rid);
			mv.addObject("DID", rid);
		}else{
			view = superviseService.showJurList(0);
			mv.addObject("DID", "");
		}

		mv.addObject("view", view);
		logger.info(" 权限视图罗列 - " + Thread.currentThread().getStackTrace()[1].getMethodName() + " - end $");
		return mv;
	}

	/**
	 * 权限参值提交
	 * @param model 模组参数
	 * @param request 请求参数
	 * @param session 权限参数
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/updateJurisdiction")
	public String updateJurisdiction( HttpServletRequest request, HttpSession session) {
		String id = request.getParameter("rid")+"";
		String[] navigateA = request.getParameterValues("navigateA");
		String[] navigateB = request.getParameterValues("navigateB");
		String[] navigateC = request.getParameterValues("navigateC");
		String rRole = request.getParameter("rRole");
		String rInfo = request.getParameter("rInfo");
		String returnStr = superviseService.updateList(rRole,rInfo,navigateA,navigateB,navigateC,id);
		return returnStr;
	}
	
	/**
	 * 密码修改
	 * @param model 模组参数
	 * @param request 请求参数
	 * @param session 权限参数
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/updatePassword")
	public String updatePassword( HttpServletRequest request, HttpSession session) {
		String id = request.getParameter("rid")+"";
		String[] navigateA = request.getParameterValues("navigateA");
		String[] navigateB = request.getParameterValues("navigateB");
		String[] navigateC = request.getParameterValues("navigateC");
		String rRole = request.getParameter("rRole");
		String rInfo = request.getParameter("rInfo");
		String returnStr = superviseService.updateList(rRole,rInfo,navigateA,navigateB,navigateC,id);
		return returnStr;
	}

}
